package com.qezhhnjy.mall.member.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.member.MemberLevel;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.member.service.MemberLevelService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 会员等级 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "会员等级接口")
@Slf4j
@RequestMapping("/member-level")
public class MemberLevelController {
    @Resource
    private MemberLevelService memberLevelService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取会员等级信息")
    public BaseResult<MemberLevel> get(Long id) {
        MemberLevel memberLevel = memberLevelService.getById(id);
        return BaseResult.success(memberLevel);
    }

    @PostMapping("/save")
    @Operation(summary = "新增会员等级信息")
    public BaseResult<MemberLevel> save(@RequestBody MemberLevel memberLevel) {
        memberLevelService.save(memberLevel);
        return BaseResult.success(memberLevel);
    }

    @PutMapping("/update")
    @Operation(summary = "更新会员等级信息")
    public BaseResult<MemberLevel> update(@RequestBody MemberLevel memberLevel) {
        memberLevelService.updateById(memberLevel);
        return BaseResult.success(memberLevel);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取会员等级信息")
    public BaseResult<Page<MemberLevel>> page(@RequestBody Page<MemberLevel> page) {
        memberLevelService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除会员等级信息")
    public BaseResult<Long> delete(Long id) {
        memberLevelService.removeById(id);
        return BaseResult.success(id);
    }
}

